package com.ruoyi.project.cms.service.impl;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.cms.mapper.CmsMatterMapper;
import com.ruoyi.project.cms.domain.CmsMatter;
import com.ruoyi.project.cms.service.ICmsMatterService;

/**
 * 素材库Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-10-09
 */
@Service
public class CmsMatterServiceImpl implements ICmsMatterService 
{
    @Autowired
    private CmsMatterMapper cmsMatterMapper;

    /**
     * 查询素材库
     * 
     * @param id 素材库ID
     * @return 素材库
     */
    @Override
    public CmsMatter selectCmsMatterById(Long id)
    {
        return cmsMatterMapper.selectCmsMatterById(id);
    }

    /**
     * 查询素材库列表
     * 
     * @param cmsMatter 素材库
     * @return 素材库
     */
    @Override
    public List<CmsMatter> selectCmsMatterList(CmsMatter cmsMatter)
    {
        return cmsMatterMapper.selectCmsMatterList(cmsMatter);
    }

    /**
     * 新增素材库
     * 
     * @param cmsMatter 素材库
     * @return 结果
     */
    @Override
    public int insertCmsMatter(CmsMatter cmsMatter)
    {
        return cmsMatterMapper.insertCmsMatter(cmsMatter);
    }

    /**
     * 修改素材库
     * 
     * @param cmsMatter 素材库
     * @return 结果
     */
    @Override
    public int updateCmsMatter(CmsMatter cmsMatter)
    {
        return cmsMatterMapper.updateCmsMatter(cmsMatter);
    }

    /**
     * 批量删除素材库
     * 
     * @param ids 需要删除的素材库ID
     * @return 结果
     */
    @Override
    public int deleteCmsMatterByIds(Long[] ids)
    {
        return cmsMatterMapper.deleteCmsMatterByIds(ids);
    }

    /**
     * 删除素材库信息
     * 
     * @param id 素材库ID
     * @return 结果
     */
    @Override
    public int deleteCmsMatterById(Long id)
    {
        return cmsMatterMapper.deleteCmsMatterById(id);
    }

    @Override
    public int deleteMatterByIds(Long[] ids) {
        for (Long id:ids){
            CmsMatter cmsMatter = selectCmsMatterById(id);
            cmsMatter.setIsDel(Constants.SYS_YES);
            updateCmsMatter(cmsMatter);
        }
        return 1;
    }
}
